package com.iqismart.shorturl.listener;

import org.springframework.boot.ApplicationArguments;
import org.springframework.boot.ApplicationRunner;
import org.springframework.core.annotation.Order;
import org.springframework.stereotype.Component;

import java.util.Date;

/**
 * @Description
 * @Auther sty
 * @createTime 2019/10/14 01:45
 */
@Component
@Order(1)
public class ApplicationStartedLister implements ApplicationRunner {
    public ApplicationStartedLister() {
    }

    public void run(ApplicationArguments args) throws Exception {
        outputMessage("[INFO] System startup");
    }

    public static void outputMessage(String message) {
        String separated = "************************************************************************************************************************";
        String whitespace = " ";
        message = message + " at " + new Date() + ".";
        System.out.println(separated);
        System.out.print("*");
        int i = 1;

        int flag;
        for(flag = separated.length() - message.length(); i < flag / 2; ++i) {
            System.out.print(whitespace);
        }

        System.out.print(message);

        for(int j = 1; j < flag - i; ++j) {
            System.out.print(whitespace);
        }

        System.out.println("*");
        System.out.println(separated);
    }
}
